package cn.tedu._02notice_test.controller;

import cn.tedu._02notice_test.base.response.Jsonresult;
import cn.tedu._02notice_test.mapper.NoticeMapper;
import cn.tedu._02notice_test.pojo.dto.NoticeAddParam;
import cn.tedu._02notice_test.pojo.dto.NoticeQueryDTO;
import cn.tedu._02notice_test.pojo.entity.Notice;
import cn.tedu._02notice_test.pojo.vo.NoticeQueryVO;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

@RestController
public class NoticeController {
    @Autowired
    private NoticeMapper noticeMapper;
    @PostMapping("/v1/v2/insert")
    public String insertNotice(NoticeAddParam noticeAddParam){
        System.out.println("noticeAddParam="+noticeAddParam);
        Notice notice = new Notice();
        BeanUtils.copyProperties(noticeAddParam,notice);
        notice.setUserId(100L);
        notice.setCreateTime(new Date());
        notice.setUpdateTime(new Date());
        noticeMapper.insertNotice(notice);
        return "添加资讯成功";
    }

    @GetMapping("/v1/v2/select")
    public Jsonresult selectNotice(NoticeQueryDTO noticeQueryDTO){
        System.out.println("noticeQueryDTO="+noticeQueryDTO);
        String title = noticeQueryDTO.getTitle();
        Integer type = noticeQueryDTO.getType();
        List<NoticeQueryVO> noticeQueryVOS = noticeMapper.listselect(title,type);
        return Jsonresult.ok(noticeQueryVOS);
    }
}
